1 #include <iostream>
2 #include <iomanip>
3 #include
"bluesky.h"
4 using
namespace std;
5
6 int
reserve = 9999;
7
8
9 //********************************************************************************************
10 //fills seat array with zeros

11
12 int
seat[size];
13 void
seat_fill()
14 {
15     
for (int i = 0; i < size; i++)
16     {
17         seat[i] =
0;
18     }
19 }
20 //********************************************************************************************

21 bool
taken=false;
22 bool
seat_no(int y)
23 {
24     
25         
for (int i = 0; i < size; i++ ) //loop checks if the seat is taken or not.
26         {
27                 
if( seat[i] == -1 )
28                 {
29                 taken=
true;
30                      cout <<
"The seat is taken already. \n";
31                         cout <<
"Please choose another seat number from below."<<endl;
32             
33                 
int j = 1;
34                 
while ( j < size+1 )
35                 {
36                     
if ( seat[j-1] == -1)
37                     j++;
38                     
else
39                     {
40                         cout <<
"|" << j << "|";
41                         
if ( j%10 == 0 )
42                         cout << endl;
43                         j++;
44                     }
45                         
46                         }
47         }
48         
49         }
50
51 } //
this will print the available seat numbers only
52
53
54
55 //********************************************************************************************

56 void
menu()
57 {

58 char
choice;
59
60 do
{
61 cout <<
"\t\t ------------------------------ \n";
62 cout <<
"\t\t Make Reservation ...... '1' \n";
63 cout <<
"\t\t ------------------------------ \n";
64 cout <<
"\t\t Cancel Reservation ...... '2' \n ";
65 cout <<
"\t\t ------------------------------ \n";
66 cout <<
"\t\t Search Passenger ...... '3' \n";
67 cout <<
"\t\t ------------------------------ \n";
68 cout <<
"\t\t Change Reservation ...... '4' \n";
69 cout <<
"\t\t ------------------------------ \n";
70 cout <<
"\t\t Print a list ...... '5' \n";
71 cout <<
"\t\t ------------------------------ \n";
72 cout <<
"\t\t Print status Report ...... '6' \n ";
73 cout <<
"\t\t ------------------------------ \n";
74 cout <<
"\t\t Quit ...... '7' \n ";
75 cout <<
"\t\t ------------------------------ \n";
76 cout <<
"::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n";
77 cout <<
"\n Option :: ";
78     
79     cin >> choice;
80     choice = ((
int)(choice)-48);
81     
82     
switch (choice) //starting casefn1353.
83     {
84     
case 1: system("CLS"); bluesky.make_reservation();
85                     
break;
86     
case 2: system("CLS"); bluesky.cancel_reservation();
87                     
break;
88     
case 3: system("CLS"); bluesky.search_passenger();
89                     
break;
90     
case 4: system("CLS"); bluesky.change_reservation();
91                     
break;
92     
case 5: system("CLS"); bluesky.print_list();
93                     
break;
94     
case 6: system("CLS"); bluesky.print_report();
95                     
break;
96     
case 7: cout << "\n\nBrought To You By code-projects.org\n\n\n";
97                     
break;
98
99     
default: cout<<" Don't be like a DORK!!! \n\n";
100         
break;
101         
102                                 
103     } // Ending
case loop.
104     
105         
106     cout<<
"\n\nxxxxxxxxx:::::: PROCESS COMPLETED: NEXT NODE ENTRY:::::::xxxxxxxxx\n\n";
107     
108     cin.
get();
109     
if(cin.get()=='\n')
110         system(
"CLS");
111     
112
113
114     cout<<
"\n\n ..................... MENU OPTIONS .............................\n"<<endl;
115         
116  }
while(choice != 7 );
117
118 } // ending
void menu function
119
120 //************************************************************************
121 airlines::airlines() //Constructor sets the pointer to
null.
122 {
123     start = NULL;
124 }
125
126 //*************************************************************************

127 void
airlines:: make_reservation() //This function makes reservation.
128 {
129     
int meal_choice, x;
130         
131
132     temp =
new node; //adding new nodes.
133
134     cout<<
"\n\nEnter First Name of person: ";
135     cin>>temp->fname;
136     cout<<
"--------------------------------\n";
137
138     cout<<
"Enter Last Name of Person: ";
139     cin>>temp->lname;
140     cout<<
"--------------------------------\n";
141
142     cout<<
"Enter ID of the person: ";
143     cin>>temp->ID;
144     cout<<
"--------------------------------\n";
145
146     cout<<
"Enter Phone Number of Person: ";
147     cin>>temp->phone_num;
148     cout<<
"--------------------------------\n";
149
150     
do{
151     cout <<
"Please Enter the Seat Number: ";
152
153         cin>>x;
154         
while(x>size){
155         cout<<
" Try again:: ";
156         cin >>x;
157         }
158
159     cout<<
"--------------------------------\n";
160         
if((seat[x-1])>-1) // if seat value is 0 and more than it's is empty
161         taken =
false;
162         
else //cp
163         seat_no(x); //
if taken print available seat from another function
164     seat[x-
1] = -1; // make current seat unavailable as -1 value representation
165     temp->seat_num = x;
166     
167     }
while(taken==true);
168
169
170 //******************************************************************************
171     // prints the menu list and prompts to make a choice.
172
173         cout <<
"Please Enter Your Menu Preference from below: \n\n";
174         cout <<
" Veg ..... '1'\n";
175         cout <<
" Non-Veg ..... '2'\n";
176         cout <<
" No meal ..... '3'\n\n";
177
178         cout <<
" Your Choice :: ";
179         cin >> meal_choice;
180
181         
while(meal_choice>3 || meal_choice<1){
182         cout<<
" Try Again:: ";
183         cin>>meal_choice;
184         }
185
186         
if (meal_choice == 1)
187         temp->menu =
"veg";
188     
189         
else if (meal_choice == 2)
190         temp->menu =
"Non-Veg";
191     
192         
else
193         temp->menu =
"No meal";
194         
195             
196
197     
198     reserve++; //increments the reservation numbers
199     temp->reserve_num=reserve;
200     cout <<
"\n::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n";
201     cout <<
"YOUR RESERVATION NUMBER IS :: " << reserve << "\n\n";
202     cout <<
"::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n";
203
204     temp->next = NULL;
205
206     
if(start == NULL)
207         start = temp;
208     
else
209     {
210         temp2 = start;
211         
while (temp2->next != NULL)
212         {
213             temp2 = temp2->next;
214         }
215         temp2->next = temp;
216     }
217
218 } // insert function close
219 //********************************************************************************************

220 int
cancel=0;
221 void
airlines:: cancel_reservation() //This function cancels reservation.
222 {
int num;
223     cout <<
"Please Enter your reservation Number here: ";
224     cin >> num;
225
226         node *cur = start;
227         
if(cur!=NULL)
228         { // error checking
for empty node deletion which cause segm fault error.
229
230         
if ( start->reserve_num == num ) //first node.
231         {
232             node *del = start;
233             start = start->next;
234             delete del;
235             seat[
0] = 0;
236             cancel++;
237             
return;
238         }
239         
else
240         {
241             node *pre, *cur; //To delete a middle or last node.
242             pre = start;
243             cur = start->next;
244             
while(cur != NULL)
245             {
246                 
if ( cur->reserve_num == num )
247                         
break;
248                 pre = cur;
249                 cur = cur->next;
250             }
251             seat[cur->seat_num-
1] = 0;
252             
if (cur != NULL )
253             pre->next = cur->next;
254                 
255         }
256
257     cancel++;
258     //reserve--;
259     //temp->reserve_num=reserve;
260
261         }// error checking
if statement ends here
262         
else
263         {
264         cout<<
"!!! *** Nothing to delete or invalid entry *** !!! \n"<<endl;
265         }
266     
267 }
268 //********************************************************************************************

269 void
airlines:: search_passenger() //This function helps to search a passenger
270 {//either
by first name
271         
string fakename;
272         cout <<
"Please enter your first name here: ";
273         cin >> fakename;
274     
275         node *cur = start;
276         
while (cur != NULL)
277         {
278             
if (cur->fname == fakename) //found
279             {
280                 cout <<
"First Name : " << cur->fname << endl;
281                 cout <<
"Last Name : " << cur->lname << endl;
282                 cout <<
"ID " << cur->ID << endl;
283                 cout <<
"Phone number: " << cur->phone_num << endl;
284                 cout <<
"seat Number: " << cur->seat_num << endl;
285                 cout <<
"Reservation No. " << cur->reserve_num<< endl;
286                 
return;
287             } cur = cur->next;
288         } cout <<
" Sorry!!! NOT FOUND \n\n";
289     
290 }
291     
292 //********************************************************************************************

293 void
airlines:: change_reservation() //This function helps to upgrade class or seats.
294 //or to make more reservations.
295 {
296     
int option , next_seat;
297     cout <<
" Please enter your seat number: ";
298     cin >> option;
299     node *cur;
300     cur = start;
301
302     
while(cur != NULL)
303     {
304         
if ( cur->seat_num == option )
305             
break;
306         cur = cur->next;
307     }
308     cout <<
"Please choose another seat number from below.";
309         
int j = 1;
310         
while ( j < size+1 )
311         {
312             
if ( seat[j-1] == -1)
313             j++;
314             
else
315             {
316             cout <<
"| " << j << "|";
317             
if ( j%10 == 0 )
318             cout << endl;
319             j++;
320             }
321         }
322     cin >> next_seat;
323     seat[cur->seat_num-
1]=0;
324     cur->seat_num = next_seat;
325     seat[next_seat-
1] = -1;
326
327 }
328
329 //********************************************************************************************

330 void
airlines:: print_list() //This function prints the list of the passengers.
331 {
332     temp=start;
333     
if(temp == NULL)
334     cout<<
" End of lists"<<endl;
335     
else
336     {
int cnt = 1;
337         cout <<
"\tNumber\t First Name\t Last Name\t ID\t";
338         cout <<
"Phone Number\t seat Number\t Reservation No\t Menu\n";
339
340         
while(temp != NULL) // Display details for what temp points to
341         {
342             cout <<
"\t" << cnt <<setw(15);
343             cout << temp->fname <<setw(
15);
344             cout << temp->lname << setw(
12);
345             cout << temp->ID << setw(
12);
346             cout << temp->phone_num <<setw(
15);
347             cout << temp->seat_num <<setw(
15);
348             cout << temp->reserve_num <<setw(
12);
349             cout << temp->menu <<
"\n";
350             // Move to next node
351             temp=temp->next;
352             cnt++;
353         }
354         cout <<
"\n\n";
355
356     }
357 }
358 //********************************************************************************************

359
360 void
airlines:: print_report() //This function prints the status report of the flight.
361 {
int count = 0;
362     
for (int i =0; i < size; i++ )
363     {
364         
if (seat[i] == -1)
365             count++;
366     }
367     cout<<
"The number of reserved seats are: " << count <<endl;
368     cout<<
"The number of cancellations are: " << cancel <<endl;
369 }
370
371 //********************************************************************************************


Gõ tìm kiếm nhanh...